
namespace Patterns4Net.Core.CecilExtensions.CILPatternsMatching
{
    using System;
    using System.Diagnostics.Contracts;
    using Mono.Cecil.Cil;
    using Patterns4Net.Attributes;
    using Patterns4Net.Attributes.DesignPatterns;

    [ContractClass(typeof(InstructionMatcherContract))]
    [Strategy]
    public abstract class InstructionMatcher
    {
        protected InstructionMatcher()
        {
            Contract.Ensures(this.Found == false);
            this.Found = false;
        }

        public virtual bool Found { get; protected set; }

        public abstract bool Matches(Instruction instruction, out Instruction next);

        public virtual void Reset()
        {
            Contract.Ensures(this.Found == false);
            this.Found = false;
        }
    }

    [ContractClassFor(typeof(InstructionMatcher))]
    public abstract class InstructionMatcherContract : InstructionMatcher
    {
        public sealed override bool Matches(Instruction instruction, out Instruction next)
        {
            Contract.Requires(instruction != null);
            throw new NotImplementedException();
        }
    }
}
